package com.markhsiu.httpserver.event;

import java.io.IOException;
import java.net.Socket;

import com.markhsiu.httpserver.processor.Processor;

/**
 *  处理socket
 * @author Mark Hsiu
 *
 */
public class HttpEvent implements Runnable{

	private Socket socket;
	
	@SuppressWarnings("unused")
	private HttpEvent(){};
	
	public HttpEvent(Socket socket){
		this.socket = socket;
	}
	
	
	public void run() {
		try {
			System.out.println("  ..... start ...... \r\n");
			Request request = new Request(socket.getInputStream()).load();
			Response response = new Response(socket.getOutputStream());
			Processor.SINGLE.service(request, response);
			socket.close();
			System.out.println(" ..... end ...... \r\n");
		} catch (IOException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
			Thread.currentThread().interrupt();
		}
	}
	
}
